package com.nativetalk.controller.app.course;

import com.nativetalk.base.Page;
import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.comment.TdNtCommentCouse;
import com.nativetalk.bean.course.TdNtCoursePictureList;
import com.nativetalk.bean.course.TdNtCoursePictureListUrl;
import com.nativetalk.bean.course.TsNtCourseInfoDetail;
import com.nativetalk.bean.course.catalog.TdNtCourseCatalog;
import com.nativetalk.bean.member.TdNtMember;
import com.nativetalk.bean.member.course.TdNtMembCourseDetail;
import com.nativetalk.bean.member.setmeal.TdNtMembSetmealDetail;
import com.nativetalk.bean.website.TsNtWebSiteConfIndex;
import com.nativetalk.common.Constants;
import com.nativetalk.common.Lang;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.common.util.CommonUtil;
import com.nativetalk.common.util.JsonUtil;
import com.nativetalk.common.util.MemcachedKey;
import com.nativetalk.common.util.MemcachedUtils;
import com.nativetalk.service.member.course.search.MembCourseSearchService;
import com.nativetalk.service.member.search.MemberSearchService;
import com.nativetalk.service.membsetmeal.search.MembSetmealSearchService;
import com.nativetalk.service.study.insert.StudyTeachInsertService;
import com.nativetalk.service.teacher.search.TeacherSearchService;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

/**
 * Created by lizhun on 15/12/9.
 */
@Controller
public class CourseController {
    private static Logger logger = Logger.getLogger(CourseController.class);
    @Resource
    private MemberSearchService memberSearchService;
    @Resource
    private MembCourseSearchService membCourseSearchService;
    @Resource
    private TeacherSearchService teacherSearchService;
    @Resource
    private StudyTeachInsertService studyTeachInsertService;
    @Resource
    private MembSetmealSearchService membSetmealSearchService;

    /**
     * @return RetInfo
     * @Purpose 教材信息
     * @version 1.0
     * @time 2015-12-25
     * @author lizhun
     */
    @RequestMapping(value = "/app/1/course/index", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo list(@RequestBody Map<String, String> mapParam) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(mapParam));

            RetInfo retInfo = new RetInfo();
            Map<String, Object> map = new HashMap<>();
            Map<String, List<TdNtCoursePictureList>> tdNtCourseBannerListMap = (Map<String, List<TdNtCoursePictureList>>) MemcachedUtils.get(MemcachedKey.tdNtCourseBannerListMap);
            List<TdNtCoursePictureList> tdNtCoursePictureLists = tdNtCourseBannerListMap.get(mapParam.get("cou_id"));
            List<TdNtCoursePictureListUrl> tdNtCoursePictureListUrls = new ArrayList<>();
            for (int i = 0; i < tdNtCoursePictureLists.size(); i++) {
                TdNtCoursePictureListUrl tdNtCoursePictureListUrl = new TdNtCoursePictureListUrl();
                tdNtCoursePictureListUrl.setImg_url(tdNtCoursePictureLists.get(i).getImg_url());
                tdNtCoursePictureListUrls.add(tdNtCoursePictureListUrl);
            }
            map.put("banner", tdNtCoursePictureListUrls);
            Map<String, TsNtCourseInfoDetail> tsNtCourseInfoDetailMap = (Map<String, TsNtCourseInfoDetail>) MemcachedUtils.get(MemcachedKey.tsNtCourseInfoDetailMap);
            map.put("course", tsNtCourseInfoDetailMap.get(mapParam.get("cou_id")));
            Map<String, List<TdNtCommentCouse>> tdNtCommentCouseMap = (Map<String, List<TdNtCommentCouse>>) MemcachedUtils.get(MemcachedKey.tdNtCommentCouseMap);
            map.put("comment", tdNtCommentCouseMap.get(mapParam.get("cou_id")));
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取教程数据成功");
            retInfo.setObj(map);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

    /**
     * @return RetInfo
     * @Purpose 获取教材
     * @version 1.0
     * @time 2015-12-25
     * @author lizhun
     */
    @RequestMapping(value = "/app/1/token/course/detail", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo detail(@RequestBody Map<String, String> mapParam) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(mapParam));

            RetInfo retInfo = new RetInfo();
            Map<String, Object> map = new HashMap<>();
            Map<String, List<TdNtCoursePictureList>> tdNtCoursePictureListMap = (Map<String, List<TdNtCoursePictureList>>) MemcachedUtils.get(MemcachedKey.tdNtCoursePictureListMap);
            map.put("picture", tdNtCoursePictureListMap.get(mapParam.get("cou_id")));
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取教材数据成功");
            retInfo.setObj(map);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

    /**
     * @return RetInfo
     * @Purpose 查找老师
     * @version 2.0
     * @time 2015-12-25
     * @author lizhun
     */
    @RequestMapping(value = "/app/2/course/teachers", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo teacher(@RequestBody Page page) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(page));

            RetInfo retInfo = teacherSearchService.findTeacherCourse(page);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

    /**
     * @return RetInfo
     * @Purpose 查找课程
     * @version 2.0
     * @time 2015-12-25
     * @author lizhun
     */
    @RequestMapping(value = "/app/2/token/member/course", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo course(@RequestBody Page page,
                          @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(page));

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;

            page.setObj(tdNtMember.getMemb_id());
            RetInfo retInfo = membCourseSearchService.findTdNtMembCourseDetailByMembId(page);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

    /**
     * @return RetInfo
     * @Purpose 获取课程评论
     * @version 2.0
     * @time 2015-12-25
     * @author lizhun
     */
    @RequestMapping(value = "/app/2/course/comment", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo comment(@RequestBody Map<String, Integer> mapParam) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(mapParam));

            RetInfo retInfo = new RetInfo();
            Map<String, Object> map = new HashMap<>();
            Map<String, List<TdNtCommentCouse>> tdNtCommentCouseMap = (Map<String, List<TdNtCommentCouse>>) MemcachedUtils.get(MemcachedKey.tdNtCommentCouseMap);
            List<TdNtCommentCouse> tdNtCommentCouses = tdNtCommentCouseMap.get(mapParam.get("cou_id") + "");
            int totalPage;//总页数
            int pageSize = 10;
            int currentPage = mapParam.get("currentPage");
            int totalRecord = tdNtCommentCouses.size();//总条数
            if (totalRecord % pageSize == 0) {
                totalPage = totalRecord / pageSize;
            } else {
                totalPage = (totalRecord / pageSize) + 1;
            }
            if (currentPage >= totalPage) {
                currentPage = totalPage;
            }
            if (totalPage == currentPage) {
                map.put("comment", tdNtCommentCouses.subList((currentPage - 1) * pageSize, tdNtCommentCouses.size()));
            } else {
                map.put("comment", tdNtCommentCouses.subList((currentPage - 1) * pageSize, currentPage * pageSize));
            }
            map.put("totalPage", totalPage);
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取评论数据成功");
            retInfo.setObj(map);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

    /**
     * @return RetInfo
     * @Purpose 教材信息
     * @version 2.0
     * @time 2015-12-25
     * @author lizhun
     */
    @RequestMapping(value = "/app/2/course/index", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo index(@RequestBody Map<String, String> mapParam,
                         @RequestHeader(value = "version", required = false) String version,
                         @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(mapParam));

            RetInfo retInfo = new RetInfo();
            Map<String, Object> map = new HashMap<>();
            Map<String, List<TdNtCoursePictureList>> tdNtCourseBannerListMap = (Map<String, List<TdNtCoursePictureList>>) MemcachedUtils.get(MemcachedKey.tdNtCourseBannerListMap);
            List<TdNtCoursePictureList> tdNtCoursePictureLists = tdNtCourseBannerListMap.get(mapParam.get("cou_id"));
            Map<String, TsNtWebSiteConfIndex> tsNtWebSiteConfIndexMap = (Map<String, TsNtWebSiteConfIndex>) MemcachedUtils.get(MemcachedKey.tsNtWebSiteConfIndexMap);
            map.put("free", tsNtWebSiteConfIndexMap.get("9").getData_value());
            map.put("free_start", tsNtWebSiteConfIndexMap.get("10").getData_value());
            map.put("free_end", tsNtWebSiteConfIndexMap.get("11").getData_value());
            map.put("share", tsNtWebSiteConfIndexMap.get("12").getData_value());
            map.put("share_name", tsNtWebSiteConfIndexMap.get("13").getData_value());
            map.put("share_url", tsNtWebSiteConfIndexMap.get("14").getData_value());
            map.put("share_picutre", tsNtWebSiteConfIndexMap.get("15").getData_value());
            map.put("share_content", tsNtWebSiteConfIndexMap.get("16").getData_value());
            map.put("banner", tdNtCoursePictureLists);
            Map<String, TsNtCourseInfoDetail> tsNtCourseInfoDetailMap = (Map<String, TsNtCourseInfoDetail>) MemcachedUtils.get(MemcachedKey.tsNtCourseInfoDetailMap);
            map.put("course", tsNtCourseInfoDetailMap.get(mapParam.get("cou_id")));
            Map<String, List<TdNtCommentCouse>> tdNtCommentCouseMap = (Map<String, List<TdNtCommentCouse>>) MemcachedUtils.get(MemcachedKey.tdNtCommentCouseMap);

            Map<String, List<TdNtCourseCatalog>> tdNtCourseCatalogMap = (Map<String, List<TdNtCourseCatalog>>) MemcachedUtils.get(MemcachedKey.tdNtCourseCatalogMap);
            map.put("catalog", tdNtCourseCatalogMap.get(mapParam.get("cou_id")));


            /**
             * 查找前十条评论
             */
            List<TdNtCommentCouse> tdNtCommentCouses = tdNtCommentCouseMap.get(mapParam.get("cou_id"));
            int totalRecord;
            if (tdNtCommentCouses != null) {
                totalRecord = tdNtCommentCouses.size();//总条数
            } else {
                totalRecord = 0;//总条数
            }

            int totalPage;//总页数
            int pageSize = 10;
            int currentPage = 1;

            if (totalRecord % pageSize == 0) {
                totalPage = totalRecord / pageSize;
            } else {
                totalPage = (totalRecord / pageSize) + 1;
            }
            if (currentPage >= totalPage) {
                currentPage = totalPage;
            }
            if (tdNtCommentCouses == null) {
                map.put("comment", tdNtCommentCouses);
            } else if (tdNtCommentCouses.size() > 10) {
                map.put("comment", tdNtCommentCouses.subList(0, 10));
            } else {
                map.put("comment", tdNtCommentCouses);
            }
            map.put("currentPage", currentPage);
            map.put("totalPage", totalPage);
            map.put("totalRecord", totalRecord);
            TdNtMember tdNtMember = (TdNtMember) MemcachedUtils.get(token);
            Map<String, List<TdNtCoursePictureList>> tdNtCoursePictureListMap = (Map<String, List<TdNtCoursePictureList>>) MemcachedUtils.get(MemcachedKey.tdNtCoursePictureListMap);
            List<TdNtCoursePictureList> coursePictureLists = tdNtCoursePictureListMap.get(mapParam.get("cou_id"));
            if (tdNtMember != null) {
                TdNtMembCourseDetail tdNtMembCourse = membCourseSearchService.findTdNtMembCourseDetail(tdNtMember.getMemb_id(), Integer.valueOf(mapParam.get("cou_id")));
                if (tdNtMembCourse != null) {
                    map.put("studySize", tdNtMembCourse.getStudy_page());
                    map.put("coursePictureSize", coursePictureLists.size());
                } else {
                    map.put("studySize", 0);
                    map.put("coursePictureSize", coursePictureLists.size());
                }
                map.put("share_url", tsNtWebSiteConfIndexMap.get("14").getData_value() + "?invite_code="
                        + tdNtMember.getMemb_invite_code());
            } else {
                map.put("studySize", 0);
                map.put("coursePictureSize", coursePictureLists.size());
            }
            map.put("coursePicture", coursePictureLists.subList(0, 5));
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取教程数据成功");
            retInfo.setObj(map);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

    /**
     * @return RetInfo
     * @Purpose 选择老师开始学习
     * @version 2.0
     * @time 2015-03-16
     * @author lizhun
     */
    @RequestMapping(value = "/app/2/token/course/study", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo study(@RequestBody Map<String, Integer> mapParam,
                         @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(mapParam));

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;

            BigDecimal balance = memberSearchService.findMemberBalanceStudy(tdNtMember.getMemb_id());
            Map<String, TsNtWebSiteConfIndex> tsNtWebSiteConfIndexMap = (Map<String, TsNtWebSiteConfIndex>) MemcachedUtils.get(MemcachedKey.tsNtWebSiteConfIndexMap);
            RetInfo retInfo = new RetInfo();
            if (tsNtWebSiteConfIndexMap.get("9").getData_value().equals("0") &&
                    CommonUtil.isInDate(new Date(), tsNtWebSiteConfIndexMap.get("10").getData_value(), tsNtWebSiteConfIndexMap.get("11").getData_value())) {
                retInfo = studyTeachInsertService.inserttdNtMembSetmealByTea_Id
                        (tdNtMember, mapParam.get("cou_id").toString(), mapParam.get("tea_id"));
            } else {
                double sutdy_amount = Double.valueOf(tsNtWebSiteConfIndexMap.get("25").getData_value());
                TdNtMembSetmealDetail tdNtMembSetmealDetail = membSetmealSearchService.findMembSetmealByMembIdCouIdTwo(tdNtMember.getMemb_id(),
                        mapParam.get("cou_id"));
                if (tdNtMembSetmealDetail != null) {
                    if (tdNtMembSetmealDetail.getSurplus_time() > 0) {
                        retInfo = studyTeachInsertService.inserttdNtMembSetmealByTea_Id
                                (tdNtMember, mapParam.get("cou_id").toString(), mapParam.get("tea_id"));
                    } else if (balance.doubleValue() >= sutdy_amount) {
                        retInfo = studyTeachInsertService.inserttdNtMembSetmealByTea_Id
                                (tdNtMember, mapParam.get("cou_id").toString(), mapParam.get("tea_id"));
                    } else {
                        retInfo.setMark("1");
                        retInfo.setTip("您的余额不足支付一分钟费用,请先充值!");
                    }
                } else {
                    if (balance.doubleValue() >= sutdy_amount) {
                        retInfo = studyTeachInsertService.inserttdNtMembSetmealByTea_Id
                                (tdNtMember, mapParam.get("cou_id").toString(), mapParam.get("tea_id"));
                    } else {
                        retInfo.setMark("1");
                        retInfo.setTip("您的余额不足支付一分钟费用,请先充值!");
                    }
                }
            }

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }

    }

    /**
     * @return RetInfo
     * @Purpose 选择老师开始学习
     * @version 2.0
     * @time 2015-03-16
     * @author lizhun
     */
    @RequestMapping(value = "/app/3/token/course/study", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo studyThree(@RequestBody Map<String, Integer> mapParam,
                              @RequestHeader(value = "token", required = false) String token,
                              @RequestHeader(value = "version", required = true) String version) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(mapParam));

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;

            BigDecimal balance = memberSearchService.findMemberBalanceStudy(tdNtMember.getMemb_id());
            Map<String, TsNtWebSiteConfIndex> tsNtWebSiteConfIndexMap = (Map<String, TsNtWebSiteConfIndex>) MemcachedUtils.get(MemcachedKey.tsNtWebSiteConfIndexMap);
            RetInfo retInfo = new RetInfo();
            double sutdy_amount = Double.valueOf(tsNtWebSiteConfIndexMap.get("25").getData_value());
            if (tsNtWebSiteConfIndexMap.get("9").getData_value().equals("0") &&
                    CommonUtil.isInDate(new Date(), tsNtWebSiteConfIndexMap.get("10").getData_value(), tsNtWebSiteConfIndexMap.get("11").getData_value())) {
                retInfo = studyTeachInsertService.inserttdNtMembSetmealByTea_IdThree
                        (tdNtMember, mapParam.get("cou_id").toString(), mapParam.get("tea_id"), balance.doubleValue(), tsNtWebSiteConfIndexMap.get("10").getData_value(), tsNtWebSiteConfIndexMap.get("11").getData_value(), tsNtWebSiteConfIndexMap.get("9").getData_value(), sutdy_amount, version);
            } else {
                TdNtMembSetmealDetail tdNtMembSetmealDetail = membSetmealSearchService.findMembSetmealByMembIdCouIdTwo(tdNtMember.getMemb_id(),
                        mapParam.get("cou_id"));
                if (tdNtMembSetmealDetail != null) {
                    if (tdNtMembSetmealDetail.getSurplus_time() > 0) {
                        retInfo = studyTeachInsertService.inserttdNtMembSetmealThree
                                (tdNtMember, mapParam.get("cou_id").toString(), balance.doubleValue(), tsNtWebSiteConfIndexMap.get("10").getData_value(), tsNtWebSiteConfIndexMap.get("11").getData_value(), tsNtWebSiteConfIndexMap.get("9").getData_value(), sutdy_amount, version);
                    } else if (balance.doubleValue() >= sutdy_amount) {
                        retInfo = studyTeachInsertService.inserttdNtMembSetmealThree
                                (tdNtMember, mapParam.get("cou_id").toString(), balance.doubleValue(), tsNtWebSiteConfIndexMap.get("10").getData_value(), tsNtWebSiteConfIndexMap.get("11").getData_value(), tsNtWebSiteConfIndexMap.get("9").getData_value(), sutdy_amount, version);
                    } else {
                        retInfo.setMark("1");
                        retInfo.setTip("您的余额不足支付一分钟费用,请先充值!");
                    }
                } else {
                    if (balance.doubleValue() >= sutdy_amount) {
                        retInfo = studyTeachInsertService.inserttdNtMembSetmealByTea_IdThree
                                (tdNtMember, mapParam.get("cou_id").toString(), mapParam.get("tea_id"), balance.doubleValue(), tsNtWebSiteConfIndexMap.get("10").getData_value(), tsNtWebSiteConfIndexMap.get("11").getData_value(), tsNtWebSiteConfIndexMap.get("9").getData_value(), sutdy_amount, version);
                    } else {
                        retInfo.setMark("1");
                        retInfo.setTip("您的余额不足支付一分钟费用,请先充值!");
                    }
                }
            }

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }

    }

    /**
     * @return RetInfo
     * @Purpose 查找老师
     * @version 2.0
     * @time 2015-12-25
     * @author lizhun
     */
    @RequestMapping(value = "/app/3/course/teachers", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public RetInfo teacher(@RequestBody Page page,
                           @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(page));

            TdNtMember tdNtMember = (TdNtMember) MemcachedUtils.get(token);
            RetInfo retInfo = teacherSearchService.findTeacherCourseThree(page, tdNtMember);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }
}


